package LclJunitTest04;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.zone.ZoneRules;

/**
* @author  Lcl
* @date    2022/4/10
*/

public class HoldingTime {
    private ZonedDateTime startingTime;//开始通话时间
    private ZonedDateTime endingTime;//结束通话时间

    public HoldingTime(ZonedDateTime startingTime,ZonedDateTime endingTime)
    {
        this.startingTime=startingTime;
        this.endingTime=endingTime;
    }

    public long getHoldingTime()
    {
        long minute=0;
        long between;
        ZoneId zoneId=startingTime.getZone();
        ZoneRules zoneRules=zoneId.getRules();

        Boolean isDstOfStart=zoneRules.isDaylightSavings(startingTime.toInstant());
        Boolean isDstofEnd=zoneRules.isDaylightSavings(endingTime.toInstant());

        between=endingTime.toEpochSecond()-startingTime.toEpochSecond();
        if(between<0)
            minute=between/60;//得到通话时长
        else
            minute=(between+59)/60;//不到一分钟的，算一分钟
//        log.info("between:{},minute:{}",between,minute);
        if(minute>1800||minute<0)
        {
            throw new RuntimeException("通话时间不正确");
        }
        else
        {
            return minute;
        }
    }
}
